using System.Globalization;
using VSSDKAssist.Assets.Helpers;
using VSSDKAssist.Assets.ValueProviders.Base;

namespace VSSDKAssist.Assets.ValueProviders.Framework
{
	/// <summary>
	/// Value provider for a Random number
	/// </summary>
	public class RandomNumberValueProvider : ValueProviderBase
	{
		/// <summary>
		/// Called when [begin recipe].
		/// </summary>
		/// <param name="currentValue">The current value.</param>
		/// <param name="newValue">The new value.</param>
		/// <returns></returns>
		public override bool OnBeginRecipe(object currentValue, out object newValue)
		{
			newValue = null;

			if((currentValue == null) && (this.ExecutionStage != Stage.OnBeforeActions))
			{
				//Sleep to obtain a really random number because of the cpu ticks
				System.Threading.Thread.Sleep(100);
				newValue = CommonHelper.GetRandomNumber().ToString(CultureInfo.CurrentCulture);
				return true;
			}

			return false;
		}
	}
}